const path = require("path");
const webpack = require("webpack");
// const UglifyPlugin = require('uglifyjs-webpack-plugin')
function resolve(dir) {
  return path.join(__dirname, dir);
}

const isPro = process.env.NODE_ENV === "production";

// const Timestamp = new Date().getTime(); //当前时间为了防止打包缓存不刷新，所以给每个js文件都加一个时间戳
module.exports = {
  publicPath: "/",
  outputDir: "dist",
  lintOnSave: false,
  transpileDependencies: ["vue-particles", "animejs"],
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "windows.jQuery": "jquery",
        "root.jQuery": "jquery",
      }),
      new webpack.DefinePlugin({
        "process.env": {
          NODE_ENV: process.env.NODE_ENV,
        },
      }),
    ],
  },
  devServer: {
    proxy: {
      "/dataPortraits": {
        target: "http://172.20.22.36:6042",
        changeOrigin: true,
      },
    },
  },
  pwa: {
    iconPaths: {
      favicon32: "favicon.ico",
      favicon16: "favicon.ico",
      appleTouchIcon: "favicon.ico",
      maskIcon: "favicon.ico",
      msTileImage: "favicon.ico",
    },
  },
  chainWebpack: (config) => {
    config.resolve.alias
      .set("@", resolve("src"))
      .set("/", resolve("public"))
      .set("components", resolve("src/components"))
      .set("service", resolve("src/service"));
    config.module.rules.delete("eslint");

    config.module.rules.delete("svg");
    config.module
      .rule("svg-sprite-loader")
      .test(/\.svg$/)
      .include.add(resolve("src/icons")) //处理svg目录
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]",
      });
    config.module
      .rule("url-loader")
      .test(/\.(svg)(\?.*)?$/)
      .exclude.add(resolve("src/icons"))
      .end()
      .use("url-loader")
      .loader("url-loader")
      .options({
        limit: 10000,
        name: "img/[name].[hash:8].[ext]",
        esModule: false,
      });
    config.externals({
      "./cptable": "var cptable",
    });
  },
};
